package com.lx.sortsum;

import com.lx.entitys.CovidSumEntity;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: chenjiang
 * @Date: 2021/11/18/19:01
 * @Description:
 */
public class CovidSortSumMapper extends Mapper<LongWritable, Text, CovidSumEntity, Text> {
    CovidSumEntity outKey = new CovidSumEntity();
    Text outValue = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //Alabama	452734	7340
        String[] fields = value.toString().split("\t");
        outKey.setCases(Long.parseLong(fields[1]));
        outKey.setDeaths(Long.parseLong(fields[2]));
        outValue.set(fields[0]);
        context.write(outKey, outValue);
    }
}
